package com.rickpan.dto.contacts;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.rickpan.entity.User;

import java.time.LocalDateTime;

/**
 * 用户搜索结果响应DTO
 */
public class UserSearchResponse {

    private Long id;
    private String username;
    private String realName;
    private String avatarUrl;
    private User.UserType userType;
    private Boolean isFriend;
    private Boolean hasPendingRequest;
    private Boolean canSendRequest;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdAt;

    // 构造函数
    public UserSearchResponse() {}

    public UserSearchResponse(User user) {
        this.id = user.getId();
        this.username = user.getUsername();
        this.realName = user.getRealName();
        this.avatarUrl = user.getAvatarUrl();
        this.userType = user.getUserType();
        this.createdAt = user.getCreatedAt();
        // 默认值，需要在Service层设置
        this.isFriend = false;
        this.hasPendingRequest = false;
        this.canSendRequest = true;
    }

    public UserSearchResponse(User user, Boolean isFriend, Boolean hasPendingRequest, Boolean canSendRequest) {
        this(user);
        this.isFriend = isFriend;
        this.hasPendingRequest = hasPendingRequest;
        this.canSendRequest = canSendRequest;
    }

    // 静态工厂方法
    public static UserSearchResponse from(User user) {
        return new UserSearchResponse(user);
    }

    public static UserSearchResponse from(User user, Boolean isFriend, Boolean hasPendingRequest, Boolean canSendRequest) {
        return new UserSearchResponse(user, isFriend, hasPendingRequest, canSendRequest);
    }

    // Getter和Setter方法
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getAvatarUrl() {
        return avatarUrl;
    }

    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }

    public User.UserType getUserType() {
        return userType;
    }

    public void setUserType(User.UserType userType) {
        this.userType = userType;
    }

    public Boolean getIsFriend() {
        return isFriend;
    }

    public void setIsFriend(Boolean isFriend) {
        this.isFriend = isFriend;
    }

    public Boolean getHasPendingRequest() {
        return hasPendingRequest;
    }

    public void setHasPendingRequest(Boolean hasPendingRequest) {
        this.hasPendingRequest = hasPendingRequest;
    }

    public Boolean getCanSendRequest() {
        return canSendRequest;
    }

    public void setCanSendRequest(Boolean canSendRequest) {
        this.canSendRequest = canSendRequest;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    @Override
    public String toString() {
        return "UserSearchResponse{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", realName='" + realName + '\'' +
                ", avatarUrl='" + avatarUrl + '\'' +
                ", userType=" + userType +
                ", isFriend=" + isFriend +
                ", hasPendingRequest=" + hasPendingRequest +
                ", canSendRequest=" + canSendRequest +
                ", createdAt=" + createdAt +
                '}';
    }
}
